

import 'package:get/get.dart';
import 'package:mall/utils/sc/load_state_model.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

class WarpRefreshController extends RefreshController {
  WarpRefreshController({
    super.initialRefresh = true,
    super.initialRefreshStatus = RefreshStatus.idle,
    required Rx<LoadStateType> loadState,
  }) {
    //监听数据状态
   worker = ever(loadState, (callback) {
      callback.when(
        initial: () => null,
        refreshIng: () => null,
        refreshSuccess: () {
          super.refreshCompleted(resetFooterState: true);
          super.refreshToIdle();
        },
        refreshError: () => super.refreshFailed(),
        loadMoreIng: () => null,
        loadMoreSuccess: (hasMore) {
          super.loadComplete();
          if (hasMore) {
            super.resetNoData();
          } else {
            super.loadNoData();
          }
        },
        loadMoreError: () => super.loadComplete(),
      );
    });
  }


  late final Worker worker;

  void dispose() {
    super.dispose();
    worker.call();
  }
}

